package feifei.second;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/putUser.action")
public class PutUser extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
//        String username = req.getParameter("username");
//        String dateOfBirth = req.getParameter("dateOfBirth");
//        String hobbies = req.getParameter("hobbies");
//        String birthCity = req.getParameter("birthCity");
//        String gender = req.getParameter("gender");
//        User user = new User(username, dateOfBirth, hobbies, birthCity, gender);
////        HttpSession session = req.getSession();//第二道作业
////        session.setAttribute("user", user);//第二道作业
////        resp.sendRedirect(req.getContextPath()+"/homework/userInfo1.jsp");//第二道作业
//        ServletContext Context = this.getServletContext();
//        List<User> userList = (List<User>) Context.getAttribute("user");
//        for (int i = 0; i < userList.size(); i++) {
//            if (userList.get(i).getUsername().equals(username)) {
//               userList.set(i, user);
//            }
//            System.out.println("修改成功");
//        }

        //获取表单数据 id
        String id = req.getParameter("id");
        int uid = Integer.parseInt(id);
        HttpSession session = req.getSession();
        List<User> userList = (List<User>) session.getAttribute("user");
        User user = userList.get(uid);
    }
}
